	TITLE	CONSOLE SUBSYSTEM FOR SYSTEM MONITOR
;	CONSOLE I.0
;	CONSOLE SUBSYSTEM FOR THE SYSTEM MONITOR.
;
;  ********Donated to the Pascal/Z Users Group,July 1980*****
;	MODIFIED FOR C-MACRO ASSEMBLER MAY 1979
;
;
;	EXTERNAL LINKAGES TO CONSOLE I.0
;
;	CWBASE IS MONITOR VARIABLE RAM WORK AREA BASE
;	CVBASE IS VIDEO RAM AREA BASE
;	CBBASE IS CONSOLE INPUT BUFFER AREA
;
;	VIDEO RAM DEFINITION
;
VIDRAM	DEFL	CVBASE
;
;	KEYBOARD DEFINITION
;
KDPORT	DEFL	0D4H
KSPORT	DEFL	0D5H
KSMASK	DEFL	080H
;
;	LINE PRINTER DEFINITION
;
LDPORT	DEFL	0D6H
LSPORT	DEFL	0D7H
LBPORT	DEFL	0D0H
LSMASK	DEFL	080H
LBMASK	DEFL	080H
;
;	DEFINED ASCII USED INTERNALLY IN PACKAGE
;
ONCURS	DEFL	0EH	;TURN ON CURSOR
OFFCUR	DEFL	0FH	;TURN OFF CURSOR
LNFEED	DEFL	0AH	;LINE FEED
CARRET	DEFL	0DH	;CARRIAGE RETURN
ALTRET	DEFL	12H	;ALTERNATE CARRIAGE RETURN
SPGMD	DEFL	11H	;SET PAGE MODE
SSLMD	DEFL	17H	;SET SCROLL MODE
RPTCMD	DEFL	12H	;REPEAT COMMAND .. BUFFOUT
DCHARG	DEFL	07H	;DELETE CHARACTER GLOBALLY
ICHARG	DEFL	06H	;INSERT SPACES GLOBALLY
BACKSP	DEFL	1CH	;BACK SPACE, CURSOR LEFT
BKFEED	DEFL	1DH	;BACK FEED , CURSOR UP
DCHAR	DEFL	7FH	;DELETE A CHARACTER
NULL	DEFL	00H	;END OF MESSAGE .. BUFFOUT
;
;	ENTRIES TO CONSOLE I.0
;
CBASE	EQU	$
CNTRY1	JP	CINIT	;INITIALIZE THE PACKAGE
CNTRY2	JP	KSTAT	;KEY ENTRY STATUS
CNTRY3	JP	KINP1	;KEY ENTRY..WAIT FOR STOBE
CNTRY4	JP	KINP2	;KEY ENTRY..IMMEDIATE RETURN
CNRTY5	JP	OUTPT3	;PRINTER OUTPUT
CNTRY6	JP	BUFIN1	;SCREEN EDITED; BUFFERED INPUT
CNTRY7	JP	BUFIN2	;ALTERNATE BUFFERED INPUT.
CNTRY8	JP	CVADDR	;SCREEN CURSOR ADDRESSES
CNTRY9	JP	OUTPT1	;LIMITED SCREEN OUTPUT [TTY MODE]
CNTRYA	JP	OUTPT2	;FULL CONTROL SCREEN OUTPUT
CNTRYB	JP	OUTPT4	;SOFTWARE CONTROLLED OUTPUT TO 
;			 SCREEN AND/OR PRINTER
CNTRYC	JP	OUTPT5	;BUFFERED OUTPUT
;
;	RAM WORK AREAS FOR PACKAGE
;
CWORK	DEFW	CWBASE	;STARTING ADDRESS OF WORK AREA
BUFFER	DEFW	CBBASE	;STARTING ADDRESS OF I/O BUFFER
;	[BUFFER-3] IS ASSUMED TO BE STORAGE LOCATION OF
;	SIGNIFICANT NO OF BYTES IN BUFFER.
;	[BUFFER-2] IS ASSUMED TO BE STORAGE LOACTION OF
;	FIRST SIGNIFICANT BYTE IN THE BUFFER.
;
;VIDEO RAM CONSTANTS
TOP	DEFW	VIDRAM		;STARTING ADDRESS OF VIDEO RAM
BOTLT	DEFW	03C0H+VIDRAM	;ADDR. OF LAST LINE ON SCREEN
BOTRT	DEFW	03FFH+VIDRAM	;ENDING ADDRESS OF VIDEO RAM
;
;	VIDEO CONTROL VECTOR TABLE
;
TABLE	DEFB	111B	;DEL
	DEFW	RDEL	;DELETE CHARACTER COMMAND
	DEFB	000B	;^@ , NULL
	DEFW	0	;STOP BYTE OF BUFFERED OUTPUT
	DEFB	000B	;^A , SOH
	DEFW	0	;FLAG BYTE FOR MESSAGE MACRO
	DEFB	110B	;^B , STX
	DEFW	BOT	;BOTTOM-OUT CURSOR COMMAND
	DEFB	000B	;^C , ETX
	DEFW	0	;RESERVED
	DEFB	110B	;^D , E0T
	DEFW	RINS	;INSERT A BLANK IN A LINE COMMAND
	DEFB	111B	;^E , ENG
	DEFW	REVMD	;REVERSE VIDEO COMMAND
	DEFB	110B	;^F , ACK
	DEFW	GINS	;INSERT A BLANK GLOBALLY COMMAND
	DEFB	110B	;^G , BEL
	DEFW	GDEL	;DELETE A CHARACTER GLOBALLY COMMAND
	DEFB	111B	;^H , BS
	DEFW	CRSLT	;SHIFT CURSOR LEFT COMMAND(BACK-SPACE)
	DEFB	111B	;^I , HT
	DEFW	TABLT	;HORIZONTAL TAB COMMAND
	DEFB	011B	;^J , LF
	DEFW	LINEFD	;LINE FEED COMMAND
;			 (BUFF I/O - LINE CLEAR)
	DEFB	110B	;^K , VT
	DEFW	HOMEIT	;CURSOR HOME COMMAND
	DEFB	111B	;^L , FF
	DEFW	CLRIT	;CLEAR SCREEN COMMAND
	DEFB	011B	;^M , CR
	DEFW	CRGRT	;CARRAIGE RETURN COMMAND
	DEFB	110B	;^N , SO
	DEFW	CRSON	;CURSOR ON COMMAND
	DEFB	110B	;^O , SI
	DEFW	CRSOFF	;CURSOR OFF COMMAND
	DEFB	110B	;^P , DLE
	DEFW	PRTOGL	;PRINTER ON/OFF TOGGLE COMMAND
	DEFB	011B	;^Q , DC1
	DEFW	PMODE	;PAGE MODE COMMAND
	DEFB	000B	;^R , DC2
	DEFW	0	;ALTERNATE CR - UNDER BUFF I/O
;			 REPEAT COMM IN VIDPROCESSOR
	DEFB	000B	;^S , DC3
	DEFW	0	;SPEED CONTROL - SCROLLING
	DEFB	110B	;^T , DC4
	DEFW	LINSRT	;INSERT A BLANK LINE COMMAND
	DEFB	000B	;^U , NAK
	DEFW	0	;RESERVED
	DEFB	111B	;^V , SYN
	DEFW	DIRMD	;DIRECT VIDEO COMMAND
	DEFB	011B	;^W , ETB
	DEFW	SMODE	;SCROLL MODE COMMAND
	DEFB	000B	;^X , CAN
	DEFW	0	;RESERVED
	DEFB	110B	;^Y , EM
	DEFW	LDEL	;LINE DELETE COMMAND
	DEFB	000B	;^Z , SUB
	DEFW	0	;RESERVED
	DEFB	000B	;^[ , ESC
	DEFW	0	;RESERVED
	DEFB	110B	;^]-1 , FS
	DEFW	CRSLT	;CURSOR LEFT COMMAND
	DEFB	110B	;^] , GS
	DEFW	CRSUP	;CURSOR UP COMMAND
	DEFB	110B	;^^ , RS
	DEFW	CRSRT	;CURSOR RIGHT COMMAND
	DEFB	110B	;^/ , VS
	DEFW	CRSDN	;CURSOR DOWN COMMAND
	DEFB	111B	;5FH , TTY BACK SPACE
	DEFW	BSDEL	;BACK-SPACE AND DELETE
;
;	INITIALIZE THE PACKAGE
;
CINIT	PUSH	IY	;EXTERNAL ENTRY
	LD	IY,(CWORK)
	PUSH	HL
	CALL	CINIT1
	POP	HL
	POP	IY
	RET
;
CINIT1	LD	HL,(TOP)	;HOME CURSOR
	CALL	PUTC
	SUB	A
	LD	(IY+2),A	;SET TO SCROLL MODE
	LD	(IY+3),A	;TURN ON CURSOR
	LD	(IY+4),A	;SET VIDEO TO DIRECT MODE
	LD	(IY+8),34H	;SET SCROLL SPEED (MED)
	LD	(IY+9),A	;TURN OFF PRINTER
	LD	(IY+10),A	;INDICATE BUFFER EMPTY
	OUT	(0C8H),A	;INIT P-TECH VDM
	RET
	DEFB	0,0,0,0,0,0,0,0 ;PATCH AREA
	DEFB	0,0,0,0,0,0,0,0
;
;CONSOL INPUT .. 3 DIFFERENT ENTRIES
;	1..status - of key entry
;	2..stobed key entry
;	3..unstrobed entry
;
;	key data msb is masked off
;	upon return the carry flag is:
;		set if msb is high
;		cleared if msb is low
;
KSTAT	IN	A,(KSPORT)
	AND	KSMASK
	NOP		;RESERVED FOR NEG POLARITY
	NOP		;USE XOR KSMASK
	RET	Z
	LD	A,0FFH
	RET
;
KINP1	CALL	KSTAT
	JR	Z,KINP1
KINP2	IN	A,(KDPORT)
	NOP		;RESERVED FOR NEG POL
	OR	A
	RET P
	AND	7FH
	SCF
	RET
;
;	LINE PRINTER OUTPUT
;		{PRESENT CONFIGURATION IS COMPATABLE}
;		{TO THE CENTRONICS 779	      }
;
OPT3A	IN	A,(LSPORT)
	AND	LSMASK
	NOP			;RESERVED FOR NEG POL
	NOP
	JR	Z,OPT3A
	RET
;
OPT3B	IN	A,(LBPORT)
	AND	LBMASK
	NOP			;RESERVED FOR NEG POL
	NOP
	JR	Z,OPT3B
	RET
;
OUTPT3	CALL	OPT3A
	CALL	OPT3B
	LD	A,C
	NOP			;RESERVED FOR NEG POL
	OUT	(LDPORT),A
	RET
;
;	GET SCREEN CURSOR ADDRESSES
;
CVADDR	PUSH	IY
	LD	IY,(CWORK)
	CALL	GETC
	CALL	COL
	LD	C,A
	CALL	ROW
	LD	B,A
	POP	IY
	RET
;
;	BUFFERED INPUT - SCREEN EDITED
;
BUFIN1	CALL SVREG
	LD	L,(IY+11)
	LD	E,(IY+12)
	LD	D,(IY+13)
BF0	LD	A,L
	OR	A
	JR	NZ,BF1
	LD	A,(IY+10)
	OR	A
	JR	Z,BF0A
	SUB	A
	LD	(IY+10),A
	LD	A,0DH
	JR	BF2
BF0A	DEC	A
	LD	(IY+10),A
	CALL	BLDIT
	LD	HL,(BUFFER)
	EX	DE,HL
	ADD	HL,BC
	SBC	HL,DE
	LD	(IY+11),L
	LD	(IY+12),E
	LD	(IY+13),D
	JR	BF0
BF1	LD	A,(DE)
	DEC	HL
	INC	DE
	LD	(IY+11),L
	LD	(IY+12),E
	LD	(IY+13),D
BF2	POP	HL	;POP OFF PRIOR AF TO SAVE PRES. AF
	JP	EXIT3
;
;	LIMITED VIDEO OUTPUT - SCROLL MODE
;
OUTPT1	CALL	SVREG
	CALL	VIDCK
	LD	DE,EXIT1
	PUSH	DE
LVIDEO	LD	B,1
	SUB	A
	JR	JUMPTO
;
;	FULL CONTROL VIDEO OUTPUT - PAGE MODE
;
OUTPT2	CALL	SVREG
	CALL	VIDCK
	LD	DE,EXIT1
	PUSH	DE
FVIDEO	LD	B,2
	LD	A,0FFH
;
;
;	VECTOR TO COMMAND
;
JUMPTO	L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SH	DE
VOUT	LD	A,(IY+4)
	OR	A
	JR	Z,VOUT1
	LD	A,C
	CP	5FH
	JR	Z,VOUT1
	CP	7FH
	JR	Z,VOUT1
	CP	20H
	JR	C,VOUT1
	OR	80H
	LD	C,A
VOUT1	LD	A,(IY+2)
	INC	A
	JP	Z,FVIDEO
	LD	A,(IY+9)
	OR	A
	CALL	NZ,OUTPT3
	JP	LVIDEO
;
;	BUILD A LINE ON THE SCREEN
;	THEN PUT IT AWAY INTO THE BUFFER
;
;	exit upon sensing a carraige return
;
BLDIT	LD	HL,CMSG0
	CALL	VPROCR
BD0	LD	HL,CMSG1
	CALL	VPROCR	;CLEAR LINE
BD1	CALL	KINP1
	LD	C,A
	CP	LNFEED
	JR	Z,BD0
	CP	CARRET
	JR	Z,FIND1
	CP	ALTRET	;ALTERNATE CARRAIGE RETURN

	JR	Z,FIND2
BD3	CALL	VCHOUT
	JR	BD1
;
;	FIND LINE LOCATION ON SCREEN
;
FIND1	LD	BC,64
	JR	FIND
FIND2	LD	BC,128
FIND	PUSH	BC
	LD	C,OFFCUR
	CALL	VCHOUT
	CALL	CVADDR
	LD	A,L
	SUB	C
	LD	L,A
	JR	NC,FND1
	DEC	H
;
;	STUFF IT INTO COMMAND BUFFER
;
FND1	LD	DE,(BUFFER)
	POP	BC
	PUSH	BC
	PUSH	DE
	LDIR
	LD	HL,CMSG2
	CALL	VPROCR
;
;	GET	GIST OF COMMAND MESSAGE
;
	POP	DE
	POP	BC
	PUSH	DE
	LD	H,B
	LD	L,C
	ADD	HL,DE
	DEC	HL
	EX	DE,HL
	LD	A,(HL)
	CP	':'
	JR	NZ,FND2
	INC	HL
	DEC	BC
FND2	LD	A,20H
FND3	CPI
	JP	PO,BD6
	JR	Z,FND3
	DEC	HL
	INC	BC
	EX	DE,HL
FND4	CPD
	JR	Z,FND4
	INC	BC
BD6	POP	IX
	LD	(IX-1),D
	LD	(IX-2),E
	LD	(IX-3),C
	RET
;
;	GET ROW ADDRESS
;
ROW:	LD	A,03H
	AND	H
	LD	B,A
	LD	A,0C0H
	AND	L
	ADD	A,B
	RLCA
	RLCA
	CP	00H
	RET
;
;	GET COLUMN ADDRESS
;
COL:	LD	A,3FH
	AND	L
	RET
;
;	SAVE REGISTERS ON ENTRY
;
SVREG:	EX (SP),HL
	PUSH	BC
	PUSH	DE
	PUSH	IX
	PUSH	IY
	LD	IY,(CWORK)
	PUSH	AF
	PUSH	HL
	LD	HL,12
	ADD	HL,SP
	PUSH	DE
	LD	E,(HL)
	INC	HL
	LD	D,(HL)
	EX	DE,HL
	POP	DE
	RET
SREG2	EX	(SP),HL
	PUSH	BC
	PUSH	DE
	JP	(HL)
;
VIDCK	CALL	GETC
	LD	A,(BOTRT+1)
	CP	H
	JR	C,VCK1
	LD	A,(TOP+1)
	DEC	A
	CP	H
	RET C
VCK1	LD	HL,(TOP)
	CALL	PUTC
	CALL	CINIT1
	RET
;
;	RESTORE REGISTERS AND EXIT
;
EXIT1:	CALL	ON
	CALL	PUTC
EXIT2:	POP	AF
EXIT3:	POP	IY
	POP	IX
EXIT4:	POP	DE
	POP	BC
	POP	HL
	RET
EXIT5	CALL	ON
	CALL	PUTC
	JR	EXIT4
;
;	CHECK ON CONTROL CHARACTERS
;
CTRLCK	LD	A,C
	CP	7FH
	JR	NZ,CTR1
	SUB	A
	JR	CTR3
CTR1	CP	5FH
	JR	NZ,CTR2
	LD	A,21H
	JR	CTR3
CTR2	CP	20H
	RET NC
	INC	A
CTR3	SCF
	RET
;
;	SAVE CURSOR LOCATION
;
PUTC	LD	(IY),L
	LD	(IY+1),H
	RET
;
;	GET CURSOR LOCATION 
;
GETC	LD	L,(IY)
	LD	H,(IY+1)
	RET
;
;	SET/RESET PRINTER TOGGLE
;
PRTOGL	LD	A,(IY+9)
	OR	A
	JR	Z,PTGL1
	LD	(IY+9),00H
	RET
PTGL1	DEC	A
	LD	(IY+9),A
	RET
;
;	INSERT A BLANK LINE
;
LINSRT	CALL	CRGRT
	LD	B,40H
LINS1	PUSH	BC
	CALL	GINS1
	POP	BC
	DJNZ	LINS1
	RET
;
;	DELETE A LINE
;
LDEL	CALL	CRGRT
	CALL	PUTC
	LD	B,40H
LDEL1	PUSH	BC
	CALL	GDEL
	POP	BC
	DJNZ	LDEL1
	RET
;
;	BACKSPACE AND DELETE
;
BSDEL	CALL	COL
	RET Z
	CALL	OFF
	DEC	L
	CALL	PUTC
	JP	RDEL
;
;	SET TO PAGE MODE
;
PMODE	LD	(IY+2),0FFH
	LD	A,(IY+9)
	OR	A
	RET Z
	LD	C,0DH
	CALL	OUTPT3
	LD	(IY+9),00H
	RET
;
;	SET TO SCROLL MODE
;
SMODE	LD	(IY+2),00H
	RET
;
;	SET TO DIRECT VIDEO MODE
;
DIRMD	LD	(IY+4),00H
	RET
;
;	SET TO REVERSE VIDEO MODE
;
REVMD	LD	(IY+4),0FFH
	RET
;
;	TURN CURSOR ON
;
ON:	LD	A,(IY+2)
	OR	A
	JR	Z,ON1
	LD	A,(IY+3)
	OR	A
	RET NZ
ON1:	LD	A,(HL)
	OR	80H
	LD	(HL),A
	RET
	NOP
	NOP
	NOP
CRSON:	SUB	A
	LD	(IY+3),A
	CALL	ON
	RET
;
;	TURN CURSOR OFF
;
OFF:	LD	A,(HL)
	AND	7FH
	LD	(HL),A
	RET
	NOP
	NOP	
	NOP
	NOP
	NOP
CRSOFF: LD	A,0FFH
	LD	(IY+3),A
	CALL	OFF
	RET
;
;	CURSOR RIGHT
;
CRSRT	CALL	COL
	SUB	3FH
	RET Z
	CALL	OFF
	INC	L
	RET
;
;	CURSOR LEFT
;
CRSLT:	CALL	COL
	RET Z
	CALL	OFF
	DEC	L
	RET
;
;	CURSOR UP
;
CRSUP:	CALL	ROW
	RET Z
	CALL	OFF
	LD	A,L
	SUB	40H
	LD	L,A
	RET NC
	DEC	H
	RET
;
;	CURSOR DOWN
;
CRSDN	CALL	ROW
	CP	0FH
	RET Z
CDN1	CALL	OFF
	LD	A,L
	ADD	A,40H
	LD	L,A
	RET NC
	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ET
;
;	CARRAGE RETURN
;
CRGRT:	CALL	OFF
	LD	A,L
	AND	0C0H
	LD	L,A
	RET
;
;	LINEFEED
;
LINEFD: CALL	OFF
	CALL	ROW
	CP	0FH
	JP	Z,SCRLIT
	JP	CDN1
;
;	ENTER CHARACTER ON SCREEN
;
PRTCHR: LD	(HL),A
	INC	HL
	CALL	COL
	RET NZ
	CALL	ROW
	RET NZ
	LD	HL,(BOTLT)
	CALL	PUTC
	JP	SCRLIT
;
;	SCROLL SCREEN IF ALLOWED
;
SCRLIT: LD	A,(IY+2)
	INC	A
	JP	Z,SCR4
	CALL	UPONE
	CALL	KINP2
	CP	13H
	CALL	Z,KINP1
SCR0:	CP	30H
	JP	C,SCR1
	CP	38H
	JP	NC,SCR1
	SUB	30H
	RRCA
	RRCA
	RRCA
	AND	0E0H
	LD	(IY+8),A
SCR1:	LD	A,(IY+8)
	CP	00H
	JP	NZ,SCR2
	CALL	KINP1
	CP	20H
	RET Z
	CP	30H
	RET Z
	JP	SCR0
SCR2:	LD	D,A
	LD	E,00H
SCR3:	INC	E
	JP	NZ,SCR3
	INC	D
	JP	NZ,SCR3
	RET
SCR4:	CALL	COL
	LD	HL,(TOP)
	ADD	A,L
	LD	L,A
	RET
;
;	SCROLL UP ONE LINE
;
UPONE:	LD	DE,(TOP)
	LD	HL,40H
	ADD	HL,DE
	LD	BC,3C0H
	LDIR
	LD	HL,(BOTRT)
	LD	(HL),20H
	LD	BC,03FH
	LD	D,H
	LD	E,L
	DEC	DE
	LDDR
	CALL	GETC
	RET
;
;	MESSAGE MACROS FOR PACKAGE
;	(USED IN BUFFIN-BUILD)
;
;	CRLF,SET PAGE MODE
EOM	DEFL	NULL
CMSG0	DEFB	CARRET,LNFEED,SPGMD,EOM
;	CLEAR LINE
CMSG1	DEFB	CARRET,SSLMD,RPTCMD,40H,20H,SPGMD,BKFEED,EOM
;	SET SCROLL MODE
CMSG2	DEFB	ONCURS,SSLMD,EOM
